var app = getApp()
Page({
  data:{
    fileRecord:[
      {
        createTime: '12-08 00:10:12',
        pdfName: '111...111.pdf',
        wordName: '111...111.doc',
        wordUrl: 'http://123456'
      },
      {
        createTime: '12-08 00:10:12',
        pdfName: '22..22.pdf',
        wordName: '22..22.doc',
        wordUrl: 'http://123456'
      },
    ]
  },
  onLoad() {
    var token = wx.getStorageSync('token')
    var that = this
    wx.request({
      url: app.globalData.baseUrl + '/file/listRecord', 
      method: 'GET',
      header: {
        'token': token 
      },
      success (res) {
        var records = res.data.data
        if (!records) {
          records = [];
        }
        console.log(records)
        that.setData({
          fileRecord: records
        })
      },
      fail(res) {

      }
    })
  },
  /**
   * 下载并保存文件
   */
  downloadFileOpen(event){
    console.log(1234)
    console.log(event)
    let link = event.currentTarget.dataset.wordurl;
    console.log(link)
    //下载文件
    wx.downloadFile({
      url: link,
      success (res) {
        console.log(res)
        if (res.statusCode === 200) {
        const filePath = res.tempFilePath
          wx.openDocument({
            filePath: filePath,
            showMenu:true, //关键点
            success: function (res) {
              console.log('打开文档成功')
            }
          })
        }
      },
      fail(res) {
        console.log(res)
      }
    })
  },
})